package com.xx.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.xx.springboot.entity.Category;
import com.xx.springboot.entity.ResponseBo;
import com.xx.springboot.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoxiunique
 * @since 2018-08-06
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends ApiController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 添加标签功能
     * @param categoryName
     * @return
     */
    @GetMapping("/add")
    public ResponseBo add(String categoryName){
        boolean res = categoryService.add(categoryName);
        return res ? ResponseBo.ok() : ResponseBo.error();
    }

    /**
     * 查询 类型集合
     * @return
     */
    @PostMapping("/list")
    public ResponseBo list(){
        Category category = new Category();
        category.setStatus(1);
        QueryWrapper<Category> q = new QueryWrapper<>();

        List<Category> categorys = categoryService.list(q);
        return ResponseBo.ok(categorys);
    }


}

